package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.GetCategoryDealHandler;
import com.cungmua.app.model.request.GetCategoryDealRequest;
import com.cungmua.app.model.response.GetCategoryDealResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/17/14.
 */
public class GetCategoryDealTask extends AuthenticatedTask<GetCategoryDealRequest, Void, GetCategoryDealResponse> {
    private final Context context;
    private final GetCategoryDealHandler handler;

    public GetCategoryDealTask(Context context, GetCategoryDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected GetCategoryDealResponse doInBackground() throws RetrofitError {
        GetCategoryDealRequest request = params[0];

        return service.getListCategoryDeal(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(GetCategoryDealResponse response) {
        handler.onCategoryDeal(response);
    }
}

